package allwe.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ExceptionHandlerController {

    @ResponseBody
    @GetMapping("/testDemo1")
    public String testDemo1(){
        int i = 1/0;
        return "success";
    }

    @ResponseBody
    @GetMapping("/testDemo2")
    public String testDemo2(){
        Object object = null;
        object.getClass();

        return "success";
    }

    //只能对当前Controller里面的异常进行处理
//    @ExceptionHandler(value = {ArithmeticException.class})
    public ModelAndView handlerException(){
        System.out.println("VIP 出了异常默认走这里==========================");


        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/error1.jsp");
        return modelAndView;

    }
}
